
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import {toolList} from "./handControl";
import gameData from "./gameData";
import Tool from "../framework/Tool";

const {ccclass, property} = cc._decorator;

@ccclass
export default class toolMediator extends cc.Component {

    curCheckNode  : cc.Node = null;

    onLoad () {
        cc.game.on("toolAction",(action)=>{
            this.toolActionList(action);
        });
        cc.game.on("setCurCheckNode",(target)=>{
            this.curCheckNode = target.node;
        })
    }

    protected onDestroy(): void {
        cc.game.off("toolAction");
        cc.game.off("setCurCheckNode");
    }

    toolActionList(action){
        switch (action) {
            case toolList.openSwitch :
                this.curCheckNode.getComponent("switchMediator").switchAction();
                break;
            case toolList.portal :
                this.curCheckNode.getComponent("portalMediator").portalAction();
                break;
            case toolList.repeatSwitch :
                this.curCheckNode.getComponent("switchMediator").repeatSwitchAction();
                break;
            case toolList.sceneReversal :
                cc.game.emit("setReserveState");
                this.curCheckNode.getChildByName("bg").scaleX *= -1;
                this.curCheckNode.getChildByName("pic").scaleX *= -1;
                break;
            case toolList.showEggWindow :
                cc.game.emit("showEggView",2);
                break;
            case toolList.showStoneWindow:
                cc.game.emit("showEggView",3);
                break;
            case toolList.showGetEgg :
                cc.game.emit("showEggView",4);
                break;
            case toolList.showSkinPrince8 :
                cc.game.emit("showActionPrince8",2);
                break;
            case toolList.showPetPrince8 :
                cc.game.emit("showActionPrince8",3);
                break;
            case toolList.showQuestionPrince8 :
                cc.game.emit("showActionPrince8",1);
                break;
            case toolList.seeThreadPrince8 :
                cc.game.emit("showThreadPrince");
                break;
            case toolList.showScissor :
                cc.game.emit("showView",1);
                break;
            case toolList.showSword :
                cc.game.emit("showView",2);
                break;
        }
    }

}
